package com.hotel.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hotel.common.lang.Result;
import com.hotel.entity.Fee;
import com.hotel.service.FeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author
 * @since 2020-10-19
 */
@RestController
@RequestMapping("/fee")
public class FeeController {
    @Autowired
    FeeService feeService;
    //分页处理
    @GetMapping("/feePage")
    public Result list(@RequestParam(defaultValue = "1") Integer currentPage) {

        Page<Fee> page = new Page<>(currentPage, 5);
        IPage<Fee> pageData = feeService.page(page, new QueryWrapper<Fee>().orderByDesc("id"));
        return Result.succ(pageData);

    }

    //查询用户
    @GetMapping("/feeSel/{id}")
    public Result detail(@PathVariable(name = "id")  Long id) {
        System.err.println("1111111111111111");
        Fee fee = feeService.getById(id);
        System.err.println("222+333="+fee.toString());
        Assert.notNull(fee, "已删除！");
        return Result.succ(fee);
    }

    //增改
    //        @RequiresAuthentication
    @PostMapping("/edit")
    public Result edit(@Validated @RequestBody Fee fee) {
        System.err.println(fee.toString());
        feeService.saveOrUpdate(fee);
        return Result.succ("操作成功");
    }

    //修改房间状态
    @PostMapping("/updata/{id}")
    public Result updata(@PathVariable(name = "id")  Long id){
        System.err.println(id);
        Fee fee = feeService.getById(id);
        Integer feeId = fee.getId();
        feeService.updateHouse(feeId);

        return Result.succ("操作成功");
    }

}
